/*
 * @Description: 
 * @Author: zoe
 * @Date: 2024-09-29 14:50:27
 * @LastEditors: rendc
 * @LastEditTime: 2024-09-29 15:11:25
 */

import java.util.ArrayList;
import java.util.Collection;

public class Test02Collection{
    public static void main(String[] args) {
     //实例化两个集合对象。专门存放String类型元素
     Collection<String> c1 = new ArrayList<String>();
     Collection<String> c2 = new ArrayList<>();
     //分别给c1,c2添加元素
     String s1 = "hello";
     String s2 = "world";
     c1.add(s1);
     c1.add(s2);
     String s3 = "你好";
     String s4 = "hello";
     String s5 = "java";
     c2.add(s3);
     c2.add(s4);
     c2.add(s5);
     System.out.println("c1:" + c1);
     System.out.println("c2" + c2);
     //将c2中的元素全部添加到c1中
     c1.addAll(c2);
     System.out.println("c1:" + c1);
     //判断是否包含某个元素
     System.out.println(c1.contains("hello"));
     String s6 = new String("hello");
     String s7 = new String("world");
     //s1 == s6? false 所以推断contains方法用的是equals
     System.out.println(c1.contains(s6));
     System.out.println(c1.contains(s7));
     System.out.println(c1.contains(s2));
     System.out.println("c1" + c1);
     System.out.println("c1.size()" + c1.size());
     System.out.println("c2" + c2);
     c1.removeAll(c2);
     System.out.println("c1" + c1);
     System.out.println("c1.size()" + c1.size());
    }
}